﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gqq.Csharpindepth.Common;

namespace Gqq.Csharpindepth.Chapter1
{
    public class ProductCompare : IComparer
    {
        public int Compare(object x, object y)
        {
            return 0 - (((Product) x).Id - ((Product) y).Id);
        }
    }

    public class ArraylistCompare : IListCompare
    {
        public int Compare(object x, object y)
        {
            return ((Product) x).Id - ((Product) y).Id;
        }
    }

    /// <summary>
    /// 写一个实现泛型接口的类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ListCompare: IListCompare<Product>
    {
        public int Compare(Product a, Product b)
        {
//            throw new NotImplementedException();
            return a.Id - b.Id;
        }
    }

    public class StringCmp : IListCompare<string>
    {
        public int Compare(string a, string b)
        {
            return a.LastOrDefault().CompareTo(b.LastOrDefault());
        }
    }
}
